package com.example.design.tansaction.mediator;

import com.example.design.tansaction.colleague.AbstractCustomer;
import com.example.design.tansaction.colleague.Buyer;
import com.example.design.tansaction.colleague.Payer;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

// 中介者模式具体中介者
@Component
public class Mediator extends AbstractMediator {
    //关联同事类
    private AbstractCustomer buyer;
    //关联同事类
    private AbstractCustomer payer;

    public  static Map<String, Map<String, AbstractCustomer>> customerInstances = new HashMap<>();



    //覆写中介者方法
    @Override
    public void messageTransfer(String orderId, String targetCustomer, AbstractCustomer customer, String payResult) {
        if (customer instanceof Payer) {
            System.out.println("代付成功" + payer.getCustomerName() + "，订单号：" + orderId + "的支付。通知" + targetCustomer + "支付结果：" + payResult + ".");
        } else if (customer instanceof Buyer) {
            System.out.println("朋友代付：" + buyer.getCustomerName() + "转发订单" + orderId + "到用户" + targetCustomer + "进行支付");
        }
    }
}
